using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace Blood_Siege
{
    //The background screen sits behind all the other menu screens.
    //It draws a background image that remains fixed in place regardless
    //of whatever transitions the screens on top of it may be doing.
    class BackgroundScreen : GameScreen
    {
        ContentManager content;
        Texture2D backgroundTexture;

        //Constructor.
        public BackgroundScreen()
        {
            TransitionOnTime = TimeSpan.FromSeconds(0.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);
        }



        //Loads graphics content for this screen. The background texture is quite
        //big, so we use our own local ContentManager to load it. This allows us
        //to unload before going from the menus into the game itself, wheras if we
        //used the shared ContentManager provided by the Game class, the content
        //would remain loaded forever.
        public override void LoadContent()
        {
            if (content == null)
                content = new ContentManager(StateManager.Game.Services, "Content");

            backgroundTexture = content.Load<Texture2D>("MenuImages/MenuBGAll");
        }


        //Unloads graphics content for this screen.
        public override void UnloadContent()
        {
            content.Unload();
        }

        //Updates the background screen. Unlike most screens, this should not
        //transition off even if it has been covered by another screen: it is
        //supposed to be covered, after all! This overload forces the
        //coveredByOtherScreen parameter to false in order to stop the base
        //Update method wanting to transition off.
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                                       bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, false);
        }

        public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = StateManager.SpriteBatch;
            Viewport viewport = StateManager.GraphicsDevice.Viewport;
            Rectangle fullscreen = new Rectangle(0, 0, viewport.Width, viewport.Height);
            byte fade = TransitionAlpha;

            spriteBatch.Begin();

            spriteBatch.Draw(backgroundTexture, fullscreen,
                             new Color(fade, fade, fade));

            spriteBatch.End();
        }
    }
}
